import base
from imgaug import augmenters as iaa
import time
import random
import numpy as np

start = time.time()
ids = base.load_ids()
handle_count = 40

def handle(aug,key,image_count):
    for id in random.sample(ids,image_count):

        new_id = "%s-%s"%(id,key)
        # base.augmenttation_handle(id,aug,new_id,False,0.99)
        print("Spent:%f"%(time.time() -start))



aug = iaa.WithChannels(0, iaa.Add(50))                  #增量某个通道
handle(aug,'channels_0_add_50',handle_count)
aug = iaa.WithChannels(1, iaa.Add(50))                  #增量某个通道
handle(aug,'channels_1_add_50',handle_count)
aug = iaa.WithChannels(2, iaa.Add(50))                  #增量某个通道
handle(aug,'channels_2_add_50',handle_count)

aug = iaa.Grayscale(alpha=0.5)                          #灰度
handle(aug,'gray',handle_count)

aug = iaa.GaussianBlur(sigma=3)                         #高斯模糊
handle(aug,'gaussian_blur',handle_count)

aug = iaa.AverageBlur(k=20)                             #平均模糊
handle(aug,'average_blur',handle_count)

aug = iaa.MedianBlur(k=21)                              #中值模糊  必须是奇数
handle(aug,'median_blur',handle_count)

for i in range(10):
    ri = random.randint(-50, 50)
    aug = iaa.Add(ri)                                       #增亮图片
    handle(aug,'average_blur_'+str(ri),handle_count)

aug = iaa.AdditiveGaussianNoise(scale= 0.5*255)         #添加高斯噪点
handle(aug,'gaussian_noise',handle_count)

for ri in np.linspace(0.5, 2,10):
    aug = iaa.Multiply(ri)                                      #乘某个值for i in range(10):
    handle(aug,'multiply_'+str(ri),handle_count)

aug = iaa.Dropout(p=0.2)                                #按照比例将点设置0
handle(aug,'dropout',handle_count)

aug = iaa.Invert(1)                                     #颜色翻转
handle(aug,'invert',handle_count)


for ri in np.linspace(0.2, 2,30):
    aug = iaa.ContrastNormalization(ri)                    #对比度   0.2~2
    handle(aug,'contrast_'+str(ri),handle_count)

# aug = iaa.Scale(0.5)                                    #放大缩小